var mask = null;
var discount_id = null;
var xzauditstatus = null;
var bz = null;
$(function() { // 初始化内容
	mui.init();

		mask = mui.createMask(); //遮罩层
		datetime_init();
		login_user = JSON.parse(localStorage.getItem('loginUser'));
		discount_id = sessionStorage.getItem('discount_id')
		
		
		setTimeout(function() {
			loadDiscount(discount_id)
		}, 300);
	
	
})

function audit(){
	document.querySelector("#modal").classList.add("mui-active");
}

function loadDiscount(discount_id){
	var data = {};
	data['id'] = discount_id
	jQuery.ajax({
		headers: {
            'Authorization': login_user.token
        },		
	    type: "post",   
	    url : serverip + "fxgw/loadyhsp",
	    contentType : 'application/json;charset=UTF-8',
	    data: JSON.stringify(data),
	    dataType: "json",
	    timeout: 10000,
	    beforeSend: function() {
	      
	        mask.show();//显示遮罩层
	    },	                
	    success: function(res) {
	
	        mask.close();//显示遮罩层
			console.log("优惠记录======"+JSON.stringify(res));
			loadForm(res.discount_list[0]);
			var jlauditstatis  = res.discount_list[0].jlauditstatis ;
			var discounttype = res.discount_list[0].discounttype ;
			if(discounttype == "特殊优惠" && jlauditstatis!="未审核"){
				jQuery("#submit_yy").css('display',"none");
			}
				
				
			
		
	    },
	    
	    error: function(e) {

	       mask.close();//显示遮罩层
	       mui.alert('系统错误');
	       console.log(JSON.stringify(e));
	    }
	});	
}

function saveAuditResult(){
	var data = {}
	data['id'] = jQuery("#id").val();
	data['currentauditid'] = login_user.id;
	data['currentauditname'] = login_user.name;
	data['auditstatis'] = xzauditstatus
	data['aduittext'] = bz
	console.log("审核优惠记录上传====" + JSON.stringify(data));
	jQuery.ajax({
	    type: "post",
		headers: {
            'Authorization':login_user.token
        },		    
	    url : serverip + "fxxz/yhsp",
	    contentType : 'application/json;charset=UTF-8',
	    data : JSON.stringify(data),
	    dataType: "json",
	    timeout: 10000,
	    beforeSend: function(){
	      
	        mask.show();//显示遮罩层	   
	    },	                
	    success: function(data) {
	    	
	        mask.close();//显示遮罩层  	    	
	    	console.log(JSON.stringify(data));
	    	
	    	mui.alert('审核完成');
	    	
	    	setTimeout(function() {
	    		mui.back();
	    	}, 1000);
	    },
	    
	    error: function(e) {
	   
	       mask.close();//显示遮罩层
	       mui.alert('系统错误');
	       console.log("审核错误"+JSON.stringify(e));
	    }
	});	
}


function pass(){
	xzauditstatus = "校长审核通过";
	saveAuditResult()
}
function noPass(){
	xzauditstatus = "校长审核不通过";
	noPassText();
}

function noPassText(){
	var btnArray = ['取消', '确定'];
	mui.prompt('请填写不通过原因','请填写不通过原因',new Array('取消','确定'),function(e){
	    if(e.index == 1){
	        //mui.toast(e.value);	    
	        bz = e.value;
	        saveAuditResult();

	    }else{
	        mui.toast('您取消了输入');
	    }
	});
}